
//
//  YZQBigPictureDownTableViewCell.m
//  SuperNews
//
//  Created by qiang on 16/1/12.
//  Copyright © 2016年 qiang. All rights reserved.
//

#import "YZQBigPictureDownTableViewCell.h"


@interface YZQBigPictureDownTableViewCell ()
@property (nonatomic, retain)UILabel *titleL;
@property (nonatomic, retain)UIImageView *imageV;
@property (nonatomic, retain)UILabel *detailL;
@property (nonatomic, retain)UILabel *replyL;
@end
@implementation YZQBigPictureDownTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}

#pragma mark- 重写方法
- (void)createViews
{
    
    // 标题
    self.titleL = [[UILabel alloc]init];
    [self.contentView addSubview:self.titleL];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.top.equalTo(self.contentView).offset(10);
        make.right.equalTo(self.contentView).offset(-5);
        make.height.equalTo(@(15));
        
    }];
    self.titleL.font = [UIFont systemFontOfSize:16.0];
    
    // 图片
    self.imageV = [[UIImageView alloc]init];
    [self.contentView addSubview:self.imageV];
    self.imageV.backgroundColor = [UIColor grayColor];
    [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
        make.top.equalTo(self.titleL.mas_bottom).offset(10);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-60);
        
    }];
    
    // 简介
    self.detailL = [[UILabel alloc]init];
    [self.contentView addSubview:self.detailL];
    [self.detailL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.imageV);
        make.top.equalTo(self.imageV.mas_bottom).offset(10);
        make.height.equalTo(@(40));
        
    }];
    self.detailL.textColor = [UIColor colorWithWhite:0.620 alpha:1.000];
    self.detailL.numberOfLines = 0;
    self.detailL.font = [UIFont systemFontOfSize:14.0];
    
    
    // 跟贴
    self.replyL = [[UILabel alloc] init];
    [self.contentView addSubview:self.replyL];
    [self.replyL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.detailL).offset(-12);
        make.width.equalTo(@70);
        make.top.equalTo(self.detailL.mas_centerY).offset(5);
        make.height.equalTo(@20);
        
    }];
    //    self.replyL.layer = 1;
    self.replyL.textAlignment = NSTextAlignmentRight;
    self.replyL.font = [UIFont systemFontOfSize:14.0];
    self.replyL.textColor = [UIColor colorWithWhite:0.620 alpha:1.000];
    
}

- (void)setNewsM:(NewsPageModel *)newsM
{
    
    self.titleL.text = newsM.title;
    NSURL *url = [NSURL URLWithString:newsM.imgsrc];
    [self.imageV sd_setImageWithURL:url placeholderImage:nil];
    
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineSpacing = 4;
    NSDictionary *attrDict = @{
                               NSParagraphStyleAttributeName: paraStyle,
                               NSFontAttributeName: [UIFont systemFontOfSize: 14.0] };
    
    CGFloat height = [AdjustLabelWidthToFitFontAppTools heightForContent:newsM.digest width:self.contentView.frame.size.width - 100 - 10 - 2 fontSize:40];
    CGRect frame = self.detailL.frame;
    frame.size.height = height;
    self.detailL.frame = frame;
    self.detailL.attributedText = [[NSAttributedString alloc] initWithString:newsM.digest attributes: attrDict];
    if (newsM.replyCount != nil) {
        if (newsM.replyCount.integerValue >= 10000 ) {
            self.replyL.text = [NSString stringWithFormat:@"%.1ld万跟帖", newsM.replyCount.integerValue / 10000];
        }else{
            self.replyL.text = [NSString stringWithFormat:@"%@跟帖", newsM.replyCount];
        }
    }
    if ([newsM.skipType isEqualToString:@"special"])  {
        [self.replyL removeFromSuperview];
        self.replyL.text = @"专题";
        self.replyL.textColor = [UIColor redColor];
        
    }
    
}


@end
